package thread;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @User: vitobo
 * @Date: 2024-08-01
 * @Description: 阻塞式队列使用
 *
 *
 *
 *  基于标准库的阻塞队列,来实现一个生产者消费者模型;
 *
 *      put() 入队列, 带有阻塞功能
 *      take() 出队列, 带有阻塞功能
 */

public class ThreadDemo21 {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<String> blockingQueue = new LinkedBlockingQueue<>();
        blockingQueue.put("hello");

        String res = blockingQueue.take();
        System.out.println(res);

        // 阻塞
        res = blockingQueue.take();
        System.out.println(res);
    }


}


